import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/http_data.dart';
import 'package:app/src/http/bean/wroks/address_bean.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/helper/route_helper.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';

import '../../../../../http/bean/works_2023/purcontract_bean.dart';
import '../../../../../http/bean/works_2023/purorderInfo_bean.dart';
import '../../../../../http/bean/worksdo/material_requisition_bean.dart';
import '../../../../../http/bean/wroks/dispatchingaudit_bean.dart';
import '../../../../../http/bean/ywx_limit.dart';
import '../../../../../http/model/config_model.dart';
import '../../../../dialog/dailog.dart';

///采购合同审核：基本信息
class UiPurContractAudit {
  ///data 信息
  ///oldData 历史信息
  static Widget build(BuildContext context, YwxItem item, PurContractBean? data,
      PurContractBean? oldData, StateSetter setState,
      {String? title}) {
    if (data == null) {
      return AppUi.getEmptyView();
    }
    UiBase.setWidth();
    List<Widget> children = [];
    if (StringUtils.isEmpty(title)) {
      title = AppStrings.of(context).BaseInfo; //基本信息
    }
    var isGrey = false;
    var isAllowEmpty = true;
    var isForceCompare = false; //是否强制对比，新旧数据只要不一样就对比。（null和空字符也对比）
    if (oldData != null) {
      isForceCompare = true;
    }
    children.add(UiBase.title(context, title)); //标题
    children.add(UiBase.item(context, AppStrings.of(context).PurOrderCode2,
        data?.PurContractCode, oldData?.PurContractCode,
        isAllowEmpty: isAllowEmpty,
        isGrey: isGrey,
        isForceCompare: isForceCompare)); //采购合同号
    children.add(UiBase.item(
        context,
        AppStrings.of(context).MaterialTypeName,
        data?.getMaterialTypeName(context),
        oldData?.getMaterialTypeName(context),
        isAllowEmpty: isAllowEmpty,
        isBlue: false,
        isGrey: isGrey,
        isStart: true,
        isForceCompare: isForceCompare)); //物料类型
    children.add(UiBase.item(context, AppStrings.of(context).SupplierName,
        data?.SupplierName, oldData?.SupplierName,
        isAllowEmpty: isAllowEmpty,
        isBlue: false,
        isGrey: isGrey,
        isStart: true,
        isForceCompare: isForceCompare)); //供应商
    children.add(UiBase.item(context, AppStrings.of(context).ContractOutCode2,
        data?.ContractOutCode, oldData?.ContractOutCode,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: true,
        isForceCompare: isForceCompare)); //采购合同外部编号
    children.add(UiBase.item(context, AppStrings.of(context).Founder,
        data?.CreateName, oldData?.CreateName,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //创建人
    children.add(UiBase.item(context, AppStrings.of(context).CreaterDateTime,
        data?.getCreaterDateTime(), null,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: true,
        isForceCompare: false)); //创建日期 fixme 不对比。
    children.add(UiBase.item(context, AppStrings.of(context).TerminationDate,
        data?.getTerminationDate(), oldData?.getTerminationDate(),
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: true,
        isForceCompare: isForceCompare)); //供货日期
    children.add(UiBase.item(context, AppStrings.of(context).ContractAmount,
        data?.ContractAmount, oldData?.ContractAmount,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //合同金额
    children.add(UiBase.item(context, AppStrings.of(context).Address,
        data?.Address, oldData?.Address,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //联系地址
    children.add(UiBase.item(context, AppStrings.of(context).LinkMan,
        data?.LinkMan, oldData?.LinkMan,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //联系人
    children.add(UiBase.item(context, AppStrings.of(context).Telephone,
        data?.Telephone, oldData?.Telephone,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //联系电话
    children.add(UiBase.item(
        context, AppStrings.of(context).Email2, data?.Email, oldData?.Email,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //邮箱地址
    children.add(UiBase.item(context, AppStrings.of(context).PackageName,
        data?.PackageTypeName, oldData?.PackageTypeName,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: true,
        isForceCompare: isForceCompare)); //包装要求
    children.add(UiBase.item(context, AppStrings.of(context).DeliveryType,
        data?.getDeliveryType(context), oldData?.getDeliveryType(context),
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: true,
        isForceCompare: isForceCompare)); //提货方式
    children.add(UiBase.item(context, AppStrings.of(context).QualityTypeName,
        data?.QualityTypeName, oldData?.QualityTypeName,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //质量标准
    children.add(UiBase.item(context, AppStrings.of(context).SourceType,
        data?.SourceType, oldData?.SourceType,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //来源类型

    children.add(UiBase.item(context, AppStrings.of(context).CurrencyType,
        data?.CurrencyType, oldData?.CurrencyType,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: true,
        isForceCompare: isForceCompare)); //结算货币
    children.add(UiBase.item(context, AppStrings.of(context).TaxCode,
        data?.Taxcode, oldData?.Taxcode,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: true,
        isForceCompare: isForceCompare)); //税码
    children.add(UiBase.item(
        context, AppStrings.of(context).TaxRate2, data?.rate, oldData?.rate,
        unit: "%",
        isGrey: isGrey,
        isAllowEmpty: true,
        isForceCompare: isForceCompare)); //rate 汇率（现在存的税率）
    children.add(UiBase.item(context, AppStrings.of(context).CompanyBank2,
        data?.CompanyBank, oldData?.CompanyBank,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //开户行
    children.add(UiBase.item(context, AppStrings.of(context).BankAccount,
        data?.BankAccount, oldData?.BankAccount,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //银行账号
    children.add(UiBase.item(context, AppStrings.of(context).ContractTypeName,
        data?.getContractType(context), oldData?.getContractType(context),
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: false,
        isForceCompare: isForceCompare)); //合同类型
    children.add(UiBase.item(context, AppStrings.of(context).CompanyName2,
        data?.CompanyName, oldData?.CompanyName,
        isGrey: isGrey,
        isAllowEmpty: isAllowEmpty,
        isStart: true,
        isForceCompare: isForceCompare)); //采购公司
    // print("邮箱地址:${data?.Email}\t${oldData?.Email}");
    // print("银行账号:${data?.BankAccount}\t${oldData?.BankAccount}");
    // print("开户行:${data?.CompanyBank}\t${oldData?.CompanyBank}");
    // print(
    //     "合同类型:${data?.getContractType(context)}\t${oldData?.getContractType(context)}");
    // print(
    //     "采购公司:${data?.CompanyName}\t${oldData?.CompanyName}"); //fixme oldData采购公司没有。

    //查看历史合同
    children.add(UiBase.itemWithButon(
        context, AppStrings.of(context).tohistoryhetong, () {
      AppRouteHelper.goPurcontractAuditDetailsHistoryRoute(context, item, data);
    }, margin: EdgeInsets.only(top: 8, bottom: 8)));
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }
}
